import axios from 'axios'
import moment from 'moment'

axios.defaults.baseURL = '/api'

const get = (url,data)=>{
  return new Promise((resolve, reject) => {
    axios.get(url,{
      params: data
    }).then(data=>{
      if (data.data.success){
        resolve(data.data)
      }else{
        reject(data.data)
      }
    })
    .catch(e=>{
      console.error(`
[REQUEST]   ${moment().format('YYYY年MM月DD日 HH:mm:ss')}
method: GET
url: ${url}
data: ${JSON.stringify(data,null,2)}
      `)
    })
  })
}
const post = (url,data)=>{
  return new Promise((resolve, reject) => {
    axios.post(url,data).then(data=>{
      if (data.data.success){
        resolve(data.data)
      }else{
        reject(data.data)
      }
    })
    .catch(e=>{
      console.error(`
[REQUEST]   ${moment().format('YYYY年MM月DD日 HH:mm:ss')}
method: POST
url: ${url}
data: ${JSON.stringify(data,null,2)}
      `)
    })
  })
}


export const Service = {
  login(data){
    // return post('/api/user/login', data)
    return Promise.resolve({})// 测试
  },
  register(data){
    // return post('/api/user/register', data)
    return Promise.resolve({})// 测试
  },

  sendVailCode(data){
    // return post('/api/phone/vailcode', data)
    return Promise.resolve({});
  },

  resetPasswordNotLogin(data){
    return Promise.resolve({});
  }
}

export default {
  install(Vue){
    Vue.prototype.$service = Service;
  }
}